package org.itli.jnsocket.Util;

import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;

public class OrderIdGenerator {

    /**
     * 生成订单编号
     * @return 订单编号
     */
    public String generateOrderId() {
        // 生成两个随机字母
        String chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < 2; i++) {
            int index = ThreadLocalRandom.current().nextInt(chars.length());
            sb.append(chars.charAt(index));
        }

        // 获取当前时间戳
        long timestamp = System.currentTimeMillis();

        // 将时间戳转换为字符串，并确保它有8位
        String timestampStr = String.format("%08d", timestamp);

        // 生成四个随机数字
        String randomDigits = String.format("%04d", ThreadLocalRandom.current().nextInt(10000));

        // 拼接订单编号
        return sb.toString() + timestampStr + randomDigits;
    }
}